﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _5_AcademyTasks
{

    /*
     As you know in our Academy we give you some problems to solve. 
     * You must first solve problem 0. After solving each problem i, you must either move on to problem i+1 or skip ahead to problem i+2. 
     * You are not allowed to skip more than one problem. For example, {0, 2, 3, 5} is a valid order, but {0, 2, 4, 7} is not because the skip from 4 to 7 is too long.
     * You are given an array pleasantness (0-based), where pleasantness[i] indicates how much you like problem i. 
     * We will let you stop solving problems once the range of pleasantness you've encountered reaches a certain threshold.
     * Specifically, you may stop once the difference between the maximum and minimum pleasantness of the problems you've solved is greater than or equal 
     * to the integer variety. 
     * If this never happens, you must solve all the problems. 
     * Return the minimum number of problems you must solve to satisfy our requirements.
     */
    class AcademyTasks
    {
        static int[] pleasantness;
        static int min;
        static int minIndex = 0;
        static int max;
        static int maxIndex = 0;

        static void Main(string[] args)
        {
            //On the first input line you will be given the list of numbers in pleasantness separated by a comma and a space
            //On the second input line you will be given the integer variety.
            string[] pleasentnessAsString = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None);
            pleasantness = new int[pleasentnessAsString.Length];
            for (int i = 0; i < pleasentnessAsString.Length; i++)
            {
                pleasantness[i] = int.Parse(pleasentnessAsString[i]);
            }
            int variety = int.Parse(Console.ReadLine());

            min = pleasantness[0];
            max = pleasantness[0];

            for (int i = 0; i < pleasantness.Length; i++)
            {
                if (pleasantness[i] <= min)
                {
                    min = pleasantness[i];
                    minIndex = i;

                    if (max - min >= variety)
                    {
                        minMaxReached();
                        return;
                    }
                }
                else if (pleasantness[i] > max)
                {
                    max = pleasantness[i];
                    maxIndex = i;
                    if (max - min >= variety)
                    {
                        minMaxReached();
                        return;
                    }
                }
            }
            Console.WriteLine(pleasantness.Length);
        }

        static void minMaxReached() {
            int minTasksCount = 0;
            int closerIndex = Math.Min(minIndex, maxIndex);
            int fartherIndex = Math.Max(minIndex, maxIndex);
            for (int i = 0; i < closerIndex; i += 2)
            {
                minTasksCount++;
            }
            for (int i = closerIndex; i < fartherIndex; i += 2)
			{
                minTasksCount++;
			}
            minTasksCount++;
            Console.WriteLine(minTasksCount);
        }
    }
}
